#include <ansi.h>

inherit "room/room";

#define myName (string)this_player()->query_real_name()

mapping playerMoneys;

void reset(status x)
{
 if(x) return;

 set_light(1);
 set_no_clean(1);
 playerMoneys = ([ ]);

 dest_dir = ({ "room/bank", "south" });
 short_desc = "First Depository of Nirvana";
 long_desc  = "\
\
 The First Depository of Nirvana is an empty white room\n\
with a black hole in the middle of the floor.  Next\n\
to the hole is a small sign.\n";

 items = ({
  "hole",
"The black hole expands and contracts effortlessly",
  "floor",
"The floor is completely bare save for the black hole",
  "sign",
"A small sign reads:\n"+
"'deposit' money, or 'withdraw' it.\n"+
"It makes no difference to us.\n"+
"Coins do NOT save over reboot.\n"+
"                          -Management.\n"
 });
}

void init()
{
 ::init();
 if(this_player() && (this_player()->is_player()))
 {
  add_action("cmd_deposit", "deposit");
  add_action("cmd_withdraw","withdraw");
 }
}

int cmd_deposit(string str)
{
 int goldCoins;

 if(!str || !sscanf(str, "%d", goldCoins) ||
    goldCoins <= 0)
 {
  write("Usage: 'deposit <#>'\n");
  return 1;
 }

 if((int)this_player()->query_money() < goldCoins)
 {
  write("You cannot deposit that which you do not have.\n");
  return 1;
 }

 this_player()->add_money(-goldCoins);

 write("You toss "+goldCoins+" "+HIY+"gold coins"+NORM+" into "+
       "the hole.\n");
 say((string)this_player()->query_name()+" tosses a pouch of "+
      HIY+"gold coins"+NORM+" into the black hole.\n");

 tell_room(this_object(),
  HIK+"Black hole"+NORM+" burps.\n");

 playerMoneys[myName] += goldCoins;

 write("\
A voice tells you:\
  Your balance is "+playerMoneys[myName]+".\n\
  Remember, balances do NOT save during reboots, so don't forget\n\
  to log back in and get yer cash back!\n\n");

 return 1;
}

int cmd_withdraw(string str)
{
 int goldCoins;

 if(!str || !sscanf(str, "%d", goldCoins) || goldCoins <= 0)
 {
  write("Usage: 'withdraw <#>'\n");
  return 1;
 }

 if(playerMoneys[myName] < goldCoins)
 {
  write("Your balance is only "+playerMoneys[myName]+".\n"+
        "You can't withdraw that much.\n");
  return 1;
 }

 this_player()->add_money(goldCoins);

 write("You reach down into the hole and take out "+
  goldCoins+" "+HIY+"gold coins"+NORM+".\n");
 say((string)this_player()->query_name() +
  " reaches down into the black hole and takes out "+
  "a pouch of "+HIY+"gold coins"+NORM+".\n");

 playerMoneys[myName] -= goldCoins;
 write("A voice tells you:\
  Your balance is "+playerMoneys[myName]+".\n");

 return 1;
}


int query_drop_castle() { return 1; }
